package io.jft.doll.room.repository

import io.jft.doll.api.UserApi
import io.jft.doll.api.apiProvider
import com.g.base.room.repository.BaseRepository
import com.g.base.room.repository.NetworkBoundResult
import com.g.base.token.TokenManage
import com.google.gson.JsonObject

/**
 * Created by G on 2017/11/13 0013.
 */
/**
 * 登录注册验证码找回密码相关的接口
 */
class OauthRepository : BaseRepository() {
    //登录
    fun signIn(jsonObject: JsonObject) =
            NetworkBoundResult(
                    {
                        apiProvider.create(UserApi::class.java)
                                .signIn(jsonObject)
                    },
                    onRemoteSucceed = {
                        it?.apply {
                            TokenManage.saveToken(it)
                        }
                    }
            )

    //退出登录
    fun signOut() =
            NetworkBoundResult(
                    {
                        apiProvider.create(UserApi::class.java)
                                .signOut()
                    },
                    onRemoteSucceed = { TokenManage.cleanToken() })

}